package main

import (
	"fmt"
	"crypto/sha256"
)

var pc [256]byte

func init() {
	for i := range pc {
		pc[i] = pc[i/2] + byte(i&1)
	}
}

func PopCount(x [32]byte) int {
	var count int
	for _, it := range x {
		count += int(pc[it])
	}
	return count
}

// 编写一个函数，计算两个SHA256哈希码中不同bit的数目。（参考2.6.2节的PopCount函数。)

func main() {
	c1 := sha256.Sum256([]byte("x"))
	c2 := sha256.Sum256([]byte("X"))
	fmt.Printf("%x\n%x\n%t\n%T\n", c1, c2, c1 == c2, c1)
	fmt.Println()
	fmt.Println(PopCount(c1))
	fmt.Println(PopCount(c2))
}